<!DOCTYPE html>
<html>

<head lang="en">
    <title>找攻略</title>
    <meta charset="utf-8"/>

    <link rel="stylesheet" href="/js/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="/css/strategyCatalogs.css"/>
    <link rel="stylesheet" href="/css/strategyComment.css" />
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="/js/plugins/bootstrap-4.1.1-dist/css/bootstrap.min.css">
    <script src="/js/jquery/jquery.min.js"></script>
    <script src="/js/plugins/bootstrap-4.1.1-dist/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css"/>
    <link rel="stylesheet" href="/css/reset.css"/>
    <script src="/js/plugins/jrender/jrender.min.js"></script>
    <link rel="stylesheet" href="/js/plugins/jquery-confirm/css/jquery-confirm.css">
    <script src="/js/plugins/jquery-confirm/js/jquery-confirm.js"></script>
    <script src="/js/common.js"></script>
    <script src="/js/plugins/eleditor/Eleditor.min.js"></script>
    <script src="/js/plugins/eleditor/webuploader.min.js"></script>
    <link rel="stylesheet" href="/js/plugins/dialog2/dialog.css">
    <script src="/js/plugins/dialog2/dialog.min.js"></script>
    <script src="/js/plugins/jquery-form/jquery.form.js"></script>



    <script>

        $(function () {

            //检查登录状态
            function checkLogin() {
                if (userStr == null) {
                    $(document).dialog({
                        type: 'confirm',
                        style: 'IOS',
                        titleShow: false,
                        content: '登录后才能收藏和点赞哟~',
                        buttons: [
                            {
                                name: '取消',
                                callback: function () {
                                }
                            },
                            {
                                name: '确定',
                                callback: function () {
                                    window.parent.location.href = "/login.html";
                                }
                            }
                        ]
                    });
                    return;
                }

            }


            //给评论动态绑定点击事件
            $("#ofComment").on("click", ".commentBtn", function () {
                //子评论表自评论id
                var ofCommentId = $(this).attr("id");
                window.location.href = "/mine/addOfComment.html?commentId=" + params.id+
                    "&ofCommentId="+ofCommentId+"&replierId="+$(this).attr("lang")

            });

            //给点赞动态绑定点击事件
            $("#ofComment").on("click", ".likeBtn", function () {
                var ofCommentId = $(this).attr("id");
                checkLogin();
                userJSON = JSON.parse(userStr);
                $.get("/strategies/strategyOfCommentLikers/" + ofCommentId + "/" + userJSON.id, function (data) {
                    $(this).find('span').html(data);
                });
            });


            //获取当前登录用户信息
            var userStr = sessionStorage.getItem("user");
            var userJSON;

            $("#releaseComment").click(function () {
                if (userStr) {
                    userJSON = JSON.parse(userStr);
                    $("#commentId").val(params.id);
                    $("#commentatorId").val(userJSON.id);
                    /*$("#replyId").val($("#tempId").val());*/
                    $("#content").val(Edr.getContent());
                    $("#editForm").ajaxSubmit(function (data) {
                        if (data.success) {
                            $(".fa-commenting-o").attr("class", "fa fa-commenting");
                            $(document).dialog({
                                type: 'confirm',
                                style: 'IOS',
                                titleShow: false,
                                content: '发布成功!',
                                buttons: [
                                    {
                                        name: '确定',
                                        callback: function () {
                                            window.location.reload();
                                        }
                                    }

                                ]
                            });
                        }
                    });
                }
            });

            //移动富文本框插件
            var Edr = new Eleditor({
                el: '#contentEditor',
                upload: {
                    //图片上传的服务器接口
                    server: '/images',
                    //修改图片接收参数的名称
                    formName: 'pic'
                },
            });


            //评论id
            var params = getParams();

            if (params.id) {

                $.get("/strategies/strategyOfComments/" + params.id, {pageSize:0},function (data) {

                    sessionStorage.setItem("html","");
                    //freemarker来实现
                    $("#ofComment").append(data);
                    $.get("/strategies/temps",function (data) {

                        //获取temp资源
                        sessionStorage.setItem("html",data+sessionStorage.getItem("html"))
                        $("#ofComment").append(sessionStorage.getItem("html"));
                    })


                });


                $.get("/strategies/strategyComments/" + params.id, function (data) {
                    $("#comment").renderValues(data, {
                        setHref: function (ele, val) {
                            var href = $(ele).attr("href") + val;
                            $(ele).attr("href", href);
                        },
                        setStar: function (ele, val) {
                            var html = "";
                            if (val == 1) {
                                html = '<i class="fa fa-star"></i><i class="fa fa-star-o"></i><i class="fa fa-star-o"></i>' +
                                    '<i class="fa fa-star-o"></i><i class="fa fa-star-o"></i>';
                            } else if (val == 2) {
                                html = '<i class="fa fa-star"></i><i class="fa fa-star"></i><i class="fa fa-star-o"></i>' +
                                    '<i class="fa fa-star-o"></i><i class="fa fa-star-o"></i>';
                            } else if (val == 3) {
                                html = '<i class="fa fa-star"></i><i class="fa fa-star"></i><i class="fa fa-star"></i>' +
                                    '<i class="fa fa-star-o"></i><i class="fa fa-star-o"></i>';
                            } else if (val == 4) {
                                html = '<i class="fa fa-star"></i><i class="fa fa-star"></i><i class="fa fa-star"></i>' +
                                    '<i class="fa fa-star"></i><i class="fa fa-star-o"></i>';
                            } else if (val == 5) {
                                html = '<i class="fa fa-star"></i><i class="fa fa-star"></i><i class="fa fa-star"></i>' +
                                    '<i class="fa fa-star"></i><i class="fa fa-star"></i>';
                            } else {
                                html = '<i class="fa fa-star"></i><i class="fa fa-star"></i><i class="fa fa-star"></i>' +
                                    '<i class="fa fa-star-o"></i><i class="fa fa-star-o"></i>';

                            }
                            $(ele).html(html);
                        }
                    });
                });
            }
        })

    </script>


</head>

<body>
<div class="search-head">
    <div class="row nav-search">
        <div class="col">
            <a href="/index.html">
                <span><i class="fa fa-chevron-left"></i></span>
            </a>
        </div>
        <div class="col">
            <span>点评详情</span>
        </div>
        <div class="col"></div>
    </div>
</div>
    <div class="comment" id="comment">


            <div class="container" render-loop="list">
                <div class="row">
                    <div class="col-2 comment-head">
                        <!--<input type="hidden" id="tempId" render-value="list.commentator.id">-->
                        <a href="/userProfiles.html?id=" render-fun="setHerf" render-key="list.commentator.id">
                            <span  render-html="list.commentator.nickName"></span>
                            <img class="rounded-circle" render-src="list.commentator.headImgUrl">
                        </a>
                        <button class="btn" id="followBtn"><i class="fa fa-hand-o-right"> </i> 关注</button>
                    </div>
                    <div class="col">
                        <span class="comment-star" render-fun="setStar" render-key="list.star"></span>

                        <span class="comment-date" render-html="list.date"></span>
                        <div class="comment-content">
                            <p render-html="list.content"></p>
                        </div>

                        <div class="comment-link">
                            <a href="/strategyCatalogs.html?id=" render-fun="setHref" render-key="list.releasedDetail.id">
                                <img render-src="list.releasedDetail.coverUrl"> <span render-html="list.releasedDetail.title"></span>
                                <i class="fa fa-angle-right fa-2x"></i>
                            </a>
                        </div>

                    </div>
                </div>
            </div>

    </div>
<hr>
<span>所有回复...</span>
<!--freemarker拼接-->
<div class="comment" id="ofComment">

</div>


<form id="editForm" action="/strategies/strategyOfComments" method="post">
    <input type="hidden" name="comment.id" id="commentId">
    <input type="hidden" name="commentator.id" id="commentatorId">
    <!--<input type="hidden" name="replier.id" id="replyId">-->
    <input type="hidden" name="content" id="content">
    <div id="contentEditor" name="content"></div>
</form>
<div class="comment-list">
    回复楼主
</div>
<div class="operation">
    <div class="d-flex justify-content-between">
        <div class="p-2" id="releaseComment"><i class="fa fa-commenting-o"></i> 发布你的评论</div>
        <div class="p-2" id="saveComment"><i class="fa fa-star-o"></i> 收藏</div>
    </div>
</div>

</body>

</html>